var page = sm("do_Page");
var app = sm("do_App");
var nf = sm("do_Notification");
var hashdata = mm("do_HashData");
var root = ui("$");
var http = require("helper/http");
var mallUrl = require("url/mall");

var shopId = null;
var status = null;
var swtxt1 = [ 0, " ", " " ]; // 0:开关状态 1:关闭状态文字 2:开启状态文字
var status1 = '';
var params = page.getData();
shopId = params.id;
status = params.status;
deviceone.print(status,'status');
if (status == 1) {
	swtxt1 = [ 1, " ", " " ];
	status1 = 1;
} else {
	swtxt1 = [ 0, " ", " " ];
	status1 = 2;
}

//返回键
page.on("back", function() {
    app.closePage();
});

var headerAout = ui("headerAout");
var addheader = headerAout.add("header", "source://view/reuse/header.ui", 0, 0);
var header = ui("header");
ui(addheader + ".labelTitle").text = "修改店铺营业状态";
//左上角-返回
var headerLeft = ui(addheader+".headerLeft");
headerLeft.on("touch", function() {
    app.closePage();
});

//保存
var headerRight = ui(addheader+".headerRight");
var headerRight_lableNext = ui(addheader+".labelNext");
headerRight_lableNext.text = "保存";
headerRight_lableNext.visible = true;
headerRight.on("touch", function() {
	submit();
});

function submit(){
	var paramData = {
		id:shopId,
		status:status1
	};
	http.post(mallUrl.url.shop.updateStatus, paramData, function(data) {
		app.fire("fireShopUpdate",{"status":data.mallShop.status});
		app.closePage();
	});
};



var linearLayout_main = ui("do_LinearLayout_main");

/** -------------------add UI start ---------------------------**/
var switchtxt1 = linearLayout_main.add("txtswitch1","source://view/reuse/form/mutiSwitch.ui");
var switchtxtS1 = ui("txtswitch1");
var labelTitle1 = ui(switchtxt1 + ".labelTitle");
var aLayoutRoot1 = ui(switchtxt1 + ".aLayoutRoot");
aLayoutRoot1.tag=1;
switchtxtS1.bindData(hashdata);
hashdata.addData({
	"labelTitle" : "状态"
})
switchtxtS1.refreshData();

switchtxtS1.on("switchtag", function(data) {
	if (data == 0) {// 关闭，不允许别人查看
		status1 = 2;
	}
	if (data == 1) {// 打开，允许别人查看、默认是打开
		status1 = 1;
	}
});
switchtxtS1.fire("switchzt", swtxt1);

/** -------------------add UI end ---------------------------**/
